home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / LinkList.java < prev    next >
Text File  |  1998-11-01  |  1KB  |  63 lines

  1. /**
  2.  * A simple one-directional external linked list class.
  3.  */
  4.  
  5. public class LinkList extends Object
  6. {
  7.     private LinkList therest;
  8.     private Object thevalue;
  9.  
  10.     public LinkList(Object obj)
  11.     {
  12.         therest = null;
  13.         thevalue = obj;
  14.             //{{INIT_CONTROLS
  15.         //}}
  16. }
  17.  
  18.     /**
  19.      * Create a new list node; insert it at the head of the list. Return the list.
  20.      */
  21.  
  22.     public LinkList cons(Object obj)
  23.     {
  24.         LinkList newnode = new LinkList(obj);
  25.         newnode.thevalue = thevalue;
  26.         newnode.therest = therest;
  27.         therest = newnode;
  28.         thevalue = obj;
  29.         return this;
  30.     }
  31.  
  32.     /**
  33.      * The object owned by the list node
  34.      */
  35.  
  36.     public Object value()
  37.     {
  38.         return thevalue;
  39.     }
  40.  
  41.     /**
  42.      * The remainder of the list
  43.      */
  44.  
  45.     public LinkList rest()
  46.     {
  47.         return therest;
  48.     }
  49.  
  50.     /**
  51.      * Swap the values of a and b.
  52.      */
  53.     public static void swapValues(LinkList a, LinkList b)
  54.     {
  55.         Object save = a.thevalue;
  56.         a.thevalue = b.thevalue;
  57.         b.thevalue = save;
  58.     }
  59.     //{{DECLARE_CONTROLS
  60.     //}}
  61. }
  62.  
  63.